 $(document).ready(function(){

//等额本息
//每月月供额=〔贷款本金×月利率×(1＋月利率)＾还款月数〕÷〔(1＋月利率)＾还款月数-1〕
//
//每月应还利息=贷款本金×月利率×〔(1+月利率)^还款月数-(1+月利率)^(还款月序号-1)〕÷〔(1+月利率)^还款月数-1
//
//〕
//每月应还本金=贷款本金×月利率×(1+月利率)^(还款月序号-1)÷〔(1+月利率)^还款月数-1〕
//
//总利息=还款月数×每月月供额-贷款本金

//等额本金还款法:
//每月月供额=(贷款本金÷还款月数)+(贷款本金-已归还本金累计额)×月利率
//每月应还本金=贷款本金÷还款月数
//每月应还利息=剩余本金×月利率=(贷款本金-已归还本金累计额)×月利率
//每月月供递减额=每月应还本金×月利率=贷款本金÷还款月数×月利率
//总利息=〔(总贷款额÷还款月数+总贷款额×月利率)+总贷款额÷还款月数×(1+月利率)〕÷2×还款月数-总贷款额
	
	var mortgage_Calculator = localStorage.getItem("mortgage_Calculator");
	
		if(mortgage_Calculator==1 || mortgage_Calculator==2){
			
		
			var  monthly_principal = localStorage.getItem("monthly_principal");    //首月还款
 			var year2 =localStorage.getItem("year2");  //还歀年限
 			var pric2 = localStorage.getItem("pric2"); //贷款总额
 			var lending_rate = localStorage.getItem("lending_rate"); //贷款年利率
			
			if(year2 >=1){
				for(var i=1 ; i<= year2 ; i++){
					$("#year_bj").append("<option value='"+i+"'>第"+i+"年</option>")
				}
			}
			
			 $("#year_bj").on("change",function(){
			 	var flag = 0;
			 	var index = $(this).find('option:selected').index()+1;
			 	for(var i= (1+(index-1)*12) ; i<=12*index ; i++){
				
				var mon = (pric2/(year2*12))+((pric2-monthly_principal*(i-1))*(lending_rate/12));
				var mon_bj = parseFloat(mon).toFixed(2);
					
						flag++;
						$('.detail_price ul li').eq(flag-1).find('.detail_price_left').html(i+'月');
						$('.detail_price ul li').eq(flag-1).find('.detail_price_right').html(mon_bj+'元');
					
				}
			 	
			})
			
			
			for(var i= 0 ; i<=year2*12-1 ; i++){
				
				var mon = (pric2/(year2*12))+((pric2-monthly_principal*i)*(lending_rate/12));
				var mon_bj = parseFloat(mon).toFixed(2);
				
				$('.detail_price ul li').eq(i).find('.detail_price_left').html(i+1+'月');
				$('.detail_price ul li').eq(i).find('.detail_price_right').html(mon_bj+'元');
				
			}
			
		
		}else if(mortgage_Calculator==3){
			var  monthly_principal_hpf = localStorage.getItem("monthly_principal_hpf");    //月均还款本金-公积金
			var  monthly_principal_commercial = localStorage.getItem("monthly_principal_commercial");    //月均还款本金-商业贷
 			var year2 =localStorage.getItem("year2");  //还歀年限
 			var pric2 = localStorage.getItem("pric2"); //贷款总额
 			var price_hpf = localStorage.getItem("price_hpf");
			var lending_rate_hpf = localStorage.getItem("lending_rate_hpf");
			var price_commercial = localStorage.getItem("price_commercial");
			var lending_rate_commercial = localStorage.getItem("lending_rate_commercial");
			
			if(year2 >=1){
				for(var i=1 ; i<= year2 ; i++){
					$("#year_bj").append("<option value='"+i+"'>第"+i+"年</option>")
				}
			}
			
			 $("#year_bj").on("change",function(){
			 	var flag = 0;
			 	var index = $(this).find('option:selected').index()+1;
			 	for(var i= (1+(index-1)*12) ; i<=12*index ; i++){
				
				var mon = (price_hpf/(year2*12))+((price_hpf-monthly_principal_hpf*(i-1))*(lending_rate_hpf/12))+(price_commercial/(year2*12))+((price_commercial-monthly_principal_commercial*(i-1))*(lending_rate_commercial/12));
				var mon_bj = parseFloat(mon).toFixed(2);
					
						flag++;
						$('.detail_price ul li').eq(flag-1).find('.detail_price_left').html(i+'月');
						$('.detail_price ul li').eq(flag-1).find('.detail_price_right').html(mon_bj+'元');
					
				}
			 	
			})
			
			
			for(var i= 0 ; i<=year2*12-1 ; i++){
				
//				var mon = (pric2/(year2*12))+((pric2-monthly_principal*i)*(lending_rate/12));
				var mon = (price_hpf/(year2*12))+((price_hpf-monthly_principal_hpf*i)*(lending_rate_hpf/12))+(price_commercial/(year2*12))+((price_commercial-monthly_principal_commercial*i)*(lending_rate_commercial/12));
				var mon_bj = parseFloat(mon).toFixed(2);
				
				$('.detail_price ul li').eq(i).find('.detail_price_left').html(i+1+'月');
				$('.detail_price ul li').eq(i).find('.detail_price_right').html(mon_bj+'元');
				
			}
			
		}



})